import request from "./request";
let openId;
async function getOpenId(code) {
  if (!openId) {
    const response = await request({
      method: "GET",
      url: `${window.windowURL}/account/getOpenid/${code}`
    });
    openId = response.resInfo;
  }
  return openId;
}
export const AJAX = {
  // 	获取openId
  openId: getOpenId,
  // getOpenId: code => request({
  //   method: "GET",
  //   url: `${window.windowURL}/account/getOpenid/${code}`
  // }),
  // 	新增账户绑定
  addAcc: ({openid, intelligentNo, remarkName, isActive} = {}) => request({
    method: "POST",
    url: `${window.windowURL}/account/addAcc?${openid}&${intelligentNo}&${remarkName}&${isActive}`
  }),
  // // 修改账户绑定信息
  // amendMsg: ({openid, intelligentNo, remarkName, isActive} = {}) => request({
  //   method: "POST",
  //   url: `${window.windowURL}/account/updateAcc/${openid}/${intelligentNo}?${remarkName}${isActive}`
  // }),
  // 删除账户绑定信息
  removeMsg: ({openid, id} = {}) => request({
    method: "POST",
    url: `${window.windowURL}/account/delAcc?${openid}&${id}`
  }),
  // 查询账户绑定信息
  inquireMsg: openid => request({
    method: "GET",
    url: `${window.windowURL}/account/queryAcc/${openid}`
  }).then(data => data.resInfo),
  // 客户信息查询
  checkAcc: intelligentNo => request({
    method: "GET",
    url: `${window.windowURL}/account/checkAcc?${intelligentNo}`
  }),
  // 1.14	智能卡用户产品信息
  getBossAcc: intelligentNo => request({
    method: "GET",
    url: `${window.windowURL}/account/getBossAcc?${intelligentNo}`
  }).then(data => data.resInfo),
  // 缴费记录
  getRecharges: ({dateType, openId, pageNum}) => request({
    method: "GET",
    url: `${window.windowURL}/order/getRecharges?${dateType}&${openId}&${pageNum}`
  }).then(data => data.resInfo),
  //	查询电视维护费缴费选项
  getMaintenance: () => request({
    method: "GET",
    url: `${window.windowURL}/goods/getMaintenance`
  }),
  // 电视维护费充值接口
  rechargeTwo: ({openid, id, intelligentNo}) => request({
    method: "POST",
    url: `${window.windowURL}/orderPay/recharge2`,
    data: {openid, id, intelligentNo}
  }),
  // 以下商城接口
  // 寄送信息录入
  addressSend: ({contact, contactPhone, province, city, area, street, address, zipCode, isDefault, openid}) => request({
    method: "POST",
    url: `${window.windowURL}/send/addSendInfo`,
    data: {contact, contactPhone, province, city, area, street, address, zipCode, isDefault, openid}
  }),
  // 寄送信息查询
  inquireRecord: openid => request({
    method: "GET",
    url: `${window.windowURL}/send/getList/${openid}`
  }).then(data => data.resInfo),
  // 单条地址查询
  getSendById: id => request({
    method: "GET",
    url: `${window.windowURL}/send/updataSendById/${id}`
  }).then(data => data.resInfo),
  // 寄送地址删除
  delSend: id => request({
    method: "GET",
    url: `${window.windowURL}/send/delSend/${id}`
  }),
  // 寄送地址编辑
  updataSend: ({openid, id, contact, contactPhone, Province, city, area, street, address, zipCode, isDefault}) => request({
    method: "POST",
    url: `${window.windowURL}/send/updataSend`,
    data: {openid, id, contact, contactPhone, Province, city, area, street, address, zipCode, isDefault}
  }),
  // 删除订单
  delOrders: id => request({
    method: "GET",
    url: `${window.windowURL}/order/delOrders/${id}`
  }),
  // 查询商品信息
  allProduct: pageNum => request({
    method: "GET",
    url: `${window.windowURL}/goods/getGoods?${pageNum}`
  }).then(data => data.resInfo),
  // 查询商品展示图表
  productImg: goodsId => request({
    method: "GET",
    url: `${window.windowURL}/goods/getGoodsBan/${goodsId}`
  }).then(data => data.resInfo),
  // 查询商品套餐信息
  productSetMeal: parenId => request({
    method: "GET",
    url: `${window.windowURL}/goods/getPackage/${parenId}`
  }).then(data => data.resInfo),
  // 商品参数查询  商品详请查询
  getGoodsInfo: id => request({
    method: "GET",
    url: `${window.windowURL}/goods/getGoodsInfo/${id}`
  }).then(data => data.resInfo),
  // 节目列表
  programLits: pageNum => request({
    method: "GET",
    url: `${window.windowURL}/program/getList?${pageNum}`
  }).then(data => data.resInfo),
  // 节目列表详请查询
  programParticular: pid => request({
    method: "GET",
    url: `${window.windowURL}/program/getListById/${pid}`
  }).then(data => data.resInfo),
  // 订单记录查询
  getOrders: ({dateType, openId, pageNum, payStatus}) => request({
    method: "GET",
    url: `${window.windowURL}/order/getOrders?${dateType}&${openId}&${pageNum}&${payStatus}`
  }).then(data => data.resInfo),
  // 1.8	订单记录查询(单条)
  getOrder: id => request({
    method: "GET",
    url: `${window.windowURL}/order/getOrder/${id}`
  }),
  // 订单详情信息查询
  getOrderDetail: orderId => request({
    method: "GET",
    url: `${window.windowURL}/order/getOrderDetail/${orderId}`
  }),
  // 获取订商户订单号
  getOuttradeno: openid => request({
    method: "GET",
    url: `${window.windowURL}/orderPay/getOuttradeno?${openid}`
  }),
  // 1.4	商城订单立即支付接口
  immediatelyPay: ({openid, orderId}) => request({
    method: "POST",
    url: `${window.windowURL}/orderPay/kPay?${openid}&${orderId}`
  }),
  // 商城订单支付接口
  orderPay: ({openid, goodsName, orderDetJson, consigneeName,
  consigneePhone, consigneeAddress, invoiceType, companyName}) => request({
    method: "POST",
    url: `${window.windowURL}/orderPay/pay2`,
    data: {openid, goodsName, orderDetJson, consigneeName,
    consigneePhone, consigneeAddress, invoiceType, companyName}
  })
};
